﻿using System;
using System.Collections;
using System.Data;

public partial class Admin_News_QL_DanhNgon : System.Web.UI.Page
{
    Data data = new Data();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["admin"].Equals("true") == false)
            {
                Response.Redirect("../Default.aspx");
            }
            else
            {
                FillNoiDung();
            }
        }
        catch (Exception)
        {
            Response.Redirect("../Default.aspx");
            throw;
        }
    }

    private void FillNoiDung()
    {
        if (IsPostBack==false)
        {
            DataTable table = data.GetTable_By_Name("ThongTinCoDinh");
            CKEditor1.Text = table.Rows[6]["TTCoDinhNoiDung"].ToString();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            Random random = new Random();
            int _random = random.Next(100000);
            string _fileanh = FileUpload1.FileName.Split('.')[0]  + "_" + _random.ToString() +"."+ FileUpload1.FileName.Split('.')[1];
            FileUpload1.SaveAs(Server.MapPath("~/Images/DanhNgon/" + _fileanh));
            data.Edit_ThongTinCoDinh_Image(CKEditor1.Text, "DanhNgon", _fileanh);
        }
        else
        {
            data.Edit_ThongTinCoDinh(CKEditor1.Text, "DanhNgon");
        }
        Response.Redirect("Default.aspx");      
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
